package GUI;
/**
 * Managment screen in order to block parent users
  */

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class ManagmentSelParent extends JPanel {
	private JLabel lblBlockScreen = null;
	private JLabel lblSelectParent = null;
	private JComboBox selParentcB = null;
	private JButton btnBlock = null;
	public UserManagment user = null;
	public ManagmentMainMenu mmn = null;
	public Login myLoginFrame = null;
	private String name=null;

	
	
	public JComboBox getSelParentCb(ManagmentMainMenu mmn)
	{ 
		
		Vector<String> data = new Vector<String>();
		
		int i;
		
		for(i=0;i<mmn.user.data.Parents.size();i++)
		{
			data.add(mmn.user.data.Parents.get(i).FirstName+" "+mmn.user.data.Parents.get(i).LastName+" "+mmn.user.data.Parents.get(i).Pid);
		}
		if(selParentcB==null)
		{ 
		selParentcB = new JComboBox(data);
		selParentcB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				name=selParentcB.getSelectedItem().toString();
			}
		});
		selParentcB.setBounds(189, 139, 322, 22);
			
		}
		return selParentcB;
	}
	
	public JButton getBlockBtn()
	{
		if(btnBlock==null)
		{
		 btnBlock = new JButton("Block");
		 btnBlock.addActionListener(new ActionListener() {
		 	public void actionPerformed(ActionEvent e) {
		 		mmn.user.setName(name);
		 		String[] temp=mmn.user.getName().split(" ");
		 		String pid=temp[temp.length-1];
		 		mmn.user.Executed=false;
		 		mmn.myLoginFrame.client.handleMessageFromClientUI("ParentBlockForManagment "+"block "+pid); 
		 		while(!mmn.user.Executed);
		 	}
		 });
		btnBlock.setBounds(439, 264, 91, 23);
			
		}
		return btnBlock;
	}
	
	private void initialize(ManagmentMainMenu mmn)
	{
		setLayout(null);
		
		 lblBlockScreen = new JLabel("Block screen");
		lblBlockScreen.setBounds(307, 11, 59, 14);
		add(lblBlockScreen);
		
		 lblSelectParent = new JLabel("Select Parent:");
		lblSelectParent.setBounds(83, 143, 68, 14);
		add(lblSelectParent);
		add( getSelParentCb(mmn));
		add(getBlockBtn());
		
	}
	
	
	
	public ManagmentSelParent(ManagmentMainMenu mmn) {
		super();
		initialize(mmn);
		
	}
}
